local skels = {}
local DIY = require "packages/diy_utility/_base"

local fatu = fk.CreateSkill{
  name = "XD__fatu",
  attached_skill_name = "XD__fatu&",
}
Fk:loadTranslationTable{
  ["XD__fatu"] = "伐图",
  [":XD__fatu"] = "其他角色经你同意后可以使用你明置的手牌，以此法使用的牌不能选择你为目标，以此法使用的【杀】不计入出牌阶段的使用次数。",
}
fatu:addEffect("prohibit", {
    is_prohibited = function (self, from, to, card)
        if from ~= to and Fk:currentRoom():getCardOwner(card) == to and to:hasSkill(fatu.name) and table.contains(DIY.getShownCards(to), card.id) then
            return true
        end
    end,
})
table.insert(skels, fatu)

local fatu_active = fk.CreateSkill{
  name = "XD__fatu&",
}
Fk:loadTranslationTable{
  ["XD__fatu&"] = "伐图",
  [":XD__fatu&"] = "你可以经十字同意使用其明置的手牌，此牌不能指定其为目标，以此法使用的【杀】不计入次数限制。",

  ["#XD__fatu&"] = "伐图：你可以经十字同意使用其明置的手牌",
  ["#XD__fatu-choice"] = "伐图：%dest 想使用你的%arg，你可以点“取消”拒绝给其使用",
}
fatu_active:addEffect("viewas", {
    mute = true,
    pattern = ".",
    prompt = "#XD__fatu&",
    expand_pile = function (self, player)
        local cards = {}
        for _, p in ipairs(Fk:currentRoom().alive_players) do
            if p:hasSkill("XD__fatu") and p ~= player then
                table.insertTable(cards, DIY.getShownCards(p))
            end
        end
        return cards
    end,
    card_filter = function(self, player, to_select, selected)
        if #selected == 0 and Fk:currentRoom():getCardOwner(to_select) ~= player then
            local card = Fk:getCardById(to_select)
            return (Fk.currentResponsePattern == nil and player:canUse(card)) or
            (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card))
        end
    end,
    view_as = function(self, player, cards)
        if #cards ~= 1 then return end
        return Fk:getCardById(cards[1])
    end,
    before_use = function (self, player, use)
        local room = player.room
        local src = room:getPlayerById(room:getCardOwner(use.card.id).id)
        if src == nil then return "" end
        src:broadcastSkillInvoke("XD__fatu")
        room:notifySkillInvoked(src, "XD__fatu", "support")
        room:showCards(Card:getIdList(use.card))
        room:playCardEmotionAndSound(player, use.card)
        if #use.tos > 0 and not use.noIndicate then
            room:doIndicate(player, use.tos)
        end

        if not room:askToSkillInvoke(src, {
            skill_name = fatu.name,
            prompt = "#XD__fatu-choice::"..player.id..":"..use.card:toLogString(),
        }) then
            return "XD__fatu&"
        elseif use.card.trueName == "slash" then
            use.extraUse = true
        end
    end,
    enabled_at_play = function (self, player)
        return table.find(Fk:currentRoom().alive_players, function (p)
            return p ~= player and p:hasSkill("XD__fatu") and #DIY.getShownCards(p) > 0
        end)
    end,
    enabled_at_response = function (self, player, response)
        return not response and table.find(Fk:currentRoom().alive_players, function (p)
            return p ~= player and p:hasSkill("XD__fatu") and #DIY.getShownCards(p) > 0
        end)
    end,
})
fatu_active:addAI(nil, "vs_skill")
table.insert(skels, fatu_active)

return skels